package org.bw.bookstore.book.config;

import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.util.Properties;

/**
*@program: wisdom_bookstore
*@description: 文件上传设置类
*@author: 孙冬雪
*@create: 2020-10-25 14:52
*/
public class FileSystem {

    @Value("${fastdfs.connect_timeout_in_seconds}")
    public static Integer connect_timeout_in_seconds;
    @Value("${fastdfs.network_timeout_in_seconds}")
    public static Integer network_timeout_in_seconds;
    @Value("${fastdfs.charset}")
    public static String charset;
    @Value("${fastdfs.tracker_servers}")
    public static String tracker_servers;
    @Value("${fastdfs.tracker_servers_http}")
    public static String tracker_servers_http;

    public static void initByProperties(){
        Properties properties = new Properties();
        properties.setProperty("fastdfs.connect_timeout_in_seconds",String.valueOf(connect_timeout_in_seconds));
        properties.setProperty("fastdfs.network_timeout_in_seconds",String.valueOf(network_timeout_in_seconds));
        properties.setProperty("fastdfs.charset",charset);
        properties.setProperty("fastdfs.tracker_servers",tracker_servers);
        properties.setProperty("fastdfs.tracker_servers_http",tracker_servers_http);
        try {
            ClientGlobal.initByProperties(properties);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (MyException e) {
            e.printStackTrace();
        }
    }
}
